package battlebarnapplet;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;

import battlebarnserver.util.Constants;

public class DrawGraphics {
	public static void drawHealthBars(Graphics g, int pixelX, int pixelY, int maxHealth, int currentHealth) {
		int scaledHealth = currentHealth / (maxHealth / Constants.CLIENT_HEALTH_BAR_LENGTH);
		g.setColor(Color.blue);
		g.drawRect(pixelX, pixelY, Constants.CLIENT_HEALTH_BAR_LENGTH, Constants.CLIENT_HEALTH_BAR_HEIGHT);
		g.setColor(Color.green);
		g.fillRect(pixelX, pixelY, scaledHealth, Constants.CLIENT_HEALTH_BAR_HEIGHT);
		g.setColor(Color.black);
		g.setFont(Board.defaultFont);
		g.drawString(currentHealth + "hp", pixelX, pixelY + Constants.CLIENT_HEALTH_BAR_HEIGHT);

	}

	public static void drawCooldownBar(Graphics g, int pixelX, int pixelY, int cooldownTimer, Long timeRemaining) {
		int scaledCooldown = (int) (timeRemaining / (cooldownTimer / Constants.CLIENT_SHOT_COOLDOWN_BAR_LENGTH));
		if(timeRemaining < cooldownTimer) {
			g.setColor(Color.blue);
			g.drawRect(pixelX, pixelY+Constants.CLIENT_SHOT_COOLDOWN_OFFSET_Y, Constants.CLIENT_SHOT_COOLDOWN_BAR_LENGTH, Constants.CLIENT_SHOT_COOLDOWN_BAR_HEIGHT);
			g.setColor(Color.orange);
			g.fillRect(pixelX, pixelY+Constants.CLIENT_SHOT_COOLDOWN_OFFSET_Y, scaledCooldown, Constants.CLIENT_SHOT_COOLDOWN_BAR_HEIGHT);
			g.setColor(Color.black);
			g.setFont(Board.defaultFont);
			g.drawString("Shot", pixelX, pixelY+Constants.CLIENT_SHOT_COOLDOWN_OFFSET_Y+Constants.CLIENT_SHOT_COOLDOWN_BAR_HEIGHT);
		}
	}
	
	public static void drawMoveCooldownBar(Graphics g, int pixelX, int pixelY, int cooldownTimer, Long timeRemaining) {
		int scaledCooldown = (int) (timeRemaining / (cooldownTimer / Constants.CLIENT_SHOT_COOLDOWN_BAR_LENGTH));
		if(timeRemaining < cooldownTimer) {
			g.setColor(Color.blue);
			g.drawRect(pixelX, pixelY+15, Constants.CLIENT_SHOT_COOLDOWN_BAR_LENGTH, Constants.CLIENT_SHOT_COOLDOWN_BAR_HEIGHT);
			g.setColor(Color.orange);
			g.fillRect(pixelX, pixelY+15, scaledCooldown, Constants.CLIENT_SHOT_COOLDOWN_BAR_HEIGHT);
			g.setColor(Color.black);
			g.setFont(Board.defaultFont);
			g.drawString("Move", pixelX, pixelY+15+Constants.CLIENT_SHOT_COOLDOWN_BAR_HEIGHT);
		}
	}

	public static void drawLabels(Graphics g, int pixelX, int pixelY, String label) {
		g.setFont(Board.defaultFont);
		g.setColor(Color.blue);
		g.drawString(label, pixelX, pixelY - Constants.CLIENT_LABEL_YAXIS_OFFSET);
	}

	public static void drawSprite(Graphics g, int pixelX, int pixelY, Image image) {
		g.drawImage(image, pixelX, pixelY, null);
	}

	public static void drawBackground(Graphics g, Image image) {
		g.drawImage(image, 0, 0, null);
	}
	
	public static void displayWinner(Graphics g) {
			g.setColor(Color.blue);
			g.drawRect(156, 196, 200, 100);
			g.setColor(Color.yellow);
			g.fillRect(156, 196, 200, 100);
			g.setColor(Color.blue);
		   g.setFont(Board.headingFont);
			g.drawString(Board.winnerName.trim() + " wins!", 165, 230);
	}
}
